﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MISAPP.Classify.DataAccess;
using System.Data;
using MISAPP.MISInterface;

namespace MISAPP.Classify.Service
{
    public class Service_WMG006
    {
        /// <summary>
        /// CO:基金公司，Cust:客群，Fund:基金
        /// </summary>
        public enum FundType { CO,Cust,Fund};
        protected DA_WMG006 da = null;
        protected DA_WMG006 DA
        {
            get
            {
                if (da == null)
                {
                    da = new DA_WMG006();
                }
                return da;
            }
        }

        public DataSet GetCriteriaData()
        {
            return DA.GetCriteria();
        }


        public string[] GetCriteriaArray()
        {
            string[] flds = {"YYYYMM" };
            return flds;
        }

        public DataTable GetSummaryData(System.Collections.ArrayList p_criteria)
        {
            DataTable dt = null;
            try
            {                
                DA.ResetCriteria();
                List<iSelectList> criteriaList = p_criteria[0] as List<iSelectList>;
                FundType fundT = (FundType)p_criteria[1];
                SelectList SL = criteriaList[0] as SelectList;
                DA.AddCriteria(SL.GetField(), DA.GetInString(SL.GetReverse()), SL.GetListArray());
                string[] p_val = null;
                if (p_criteria[2] != null)
                {
                    p_val = p_criteria[2].ToString().Split(new char[] { '_' }
                        , StringSplitOptions.RemoveEmptyEntries);
                }
                dt = DA.GetSummaryData(fundT.ToString(),SL.GetListArray(), p_val);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return dt;
        }

        public DataTable GetReturnata(System.Collections.ArrayList p_criteria)
        {
            List<iSelectList> criteriaList = p_criteria[0] as List<iSelectList>;
            SelectList SL = criteriaList[0] as SelectList;
            string[] months = SL.GetListArray();
            DA.ResetCriteria();
            DA.AddCriteria(SL.GetField(), DA.GetInString(SL.GetReverse()), SL.GetListArray());
            return DA.GetReturnata(months); ;
        }

        /// <summary>
        /// 庫存基金排名前十大
        /// </summary>
        /// <param name="p_criteria"></param>
        /// <returns></returns>
        public DataTable GetStockTopTen(string p_month)
        {
            string month = GetStockTopTenYearMonth(p_month);
            string[] months = month.Split(new char[] { ',' }
                , StringSplitOptions.None);
            return DA.GetStockTopTen(months,p_month);
        }

        public string GetStockTopTenYearMonth(string p_month)
        {
            string month = string.Format(@"{0}01,{0}02,{0}03,{0}04,{0}05,{0}06,{0}07,{0}08,{0}09,{0}10,{0}11,{0}12"
                , p_month.Substring(0,4));
            return month;
        }
    }
}
